define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echarts-theme', 'template'], function ($, undefined, Backend, Datatable, Table, Echarts, undefined, Template) {
	
	/* 获取从后端tdsum.php传过来的数据 */
	
	var obj=eval(Config.demo);
	var dates=new Array;
	var normals=new Array;
	var faults=new Array;
	var OffEquips=new Array;
	var order='';
	var phivrange=new Array;
	var phivnumber=new Array;
	var creexy = new Array();
	var creeheadxy = new Array();
	var creeheadA = new Array();
	var xAx = ['亮度','色区','电压'];
	var YieldS = new Array();
	var Proportion = new Array();
	
	//$("#equips").val("9999999999");
    var Controller = {
        index: function () {
			
			
		/* 测试------------- */
			
		/* ---------------------------------------- */
		
		
		/* --------------维修首件停机分钟数及停机 fixfaultsminutestc*/
		
		/* ----------------测试 fixfaults*/
		
		
		// 基于准备好的dom，初始化echarts实例---柏拉图
		// var myChartRa1 = Echarts.init(document.getElementById('echartRa1'), 'dark');
		// var myChartFlux = Echarts.init(document.getElementById('echartFlux'), 'dark');
		// var myChartVF = Echarts.init(document.getElementById('echartVF'), 'dark');
		// var myChartColor = Echarts.init(document.getElementById('echartColor'), 'dark');
		// /*var myChart1 = Echarts.init(document.getElementById('echart1'), 'walden');
		// 柱状图数据*/
		// var myChartRa = Echarts.init(document.getElementById('echartRa'), 'dark');
		// var myChartR9 = Echarts.init(document.getElementById('echartR9'), 'dark');
		// var myChartPhiv = Echarts.init(document.getElementById('echartPhiv'), 'dark');
		// var myChartVFRange = Echarts.init(document.getElementById('echartVFRange'), 'dark');
		// var myChartLdom = Echarts.init(document.getElementById('echartLdom'), 'dark');
		// var myChartVflow = Echarts.init(document.getElementById('echartVflow'), 'dark');
		// var myCharttest = Echarts.init(document.getElementById('echarttest'), 'dark');
		
		var test = Echarts.init(document.getElementById('test'), 'dark');
		
		// var parent=document.getElementById("div1");
		// 13 /*找到子元素*/
		// 14 var child=document.getElementById("p1");
		// 15 /*将子元素从父元素中删除*/
		// 16 parent.removeChild(child);
		
		//--------------------------------
		var colors=["red","blue","green","black","orange","purple"]
		var phivarr = [];
		var phivvalue=[];
		var Percen=[];
		//testchars(test);
		// 指定图表的配置项和数据-------柏拉图--------------------
		
		getyielddate();
		
		
		$("#query").click(function() {
			order=$("#order").val()
			console.log(order);
			$.ajax({
				type: 'POST',
				url: "http://172.31.3.27:84/index.php/fastadmin/Orderyield/getyield",
				data: "OrderNumber=" + order,
				dataType: "JSON",
				success: function(ret) {
					var objs=eval(ret['yield'][0]);
					console.log(objs);
					$("#QTY").html('已扫描数:&nbsp;&nbsp;'+objs['QTY']+'K');
					$("#yield").html('等内良率:&nbsp;&nbsp;'+(objs['yield']/objs['QTY']).toFixed(3)+'%');
					testchars(test,objs);
					//-------------------------------------------------------
					// var Part=$("<td id='"+'PartNumber'+i+"'></td>").append(PartNumber[i]);
					// $("<tr id='"+'COB'+i+"'></tr>")
								// .append(number).append(insideQrCode).append(Part)
								// .append(Model1).append(Model2)
								// .appendTo("#dats_table tbody ");//.insertBefore($("#dats_table tbody 
					//-----------------------------------------------------------
					
					
				}
			});
		});
	
		
		function getyielddate(){
			
			$.ajax({
				type: 'POST',
				url: "http://172.31.3.27:84/index.php/fastadmin/Orderyield/getyielddate",
				data: "",
				dataType: "JSON",
				success: function(ret) {
					var objs=eval(ret['yield'][0]);
					testchars(test,objs);
					//-------------------------------------------------------
					//var test = Echarts.init(document.getElementById('test'), 'dark');
					// var Part=$("<td id='"+'PartNumber'+i+"'></td>").append(PartNumber[i]);
					// $("<tr id='"+'COB'+i+"'></tr>")
								// .append(number).append(insideQrCode).append(Part)
								// .append(Model1).append(Model2)
								// .appendTo("#dats_table tbody ");//.insertBefore($("#dats_table tbody 
					//------<div id="test" style="height:450px;width:110%;"></div>---------------------------------------------
					for (var i=1;i<ret['yield'].length;i++){
						
						var infor = $("<div id='"+ret['yield'][i]['OrderNumber']+"'style='"+'height:450px;width:110%;'+"'></div></div>")
						var testssss="<div id='"+ret['yield'][i]['OrderNumber']+"'style='"+'height:450px;width:110%;'+"'></div></div>";
						$("<div class='"+'col-lg-5 col-xs-8 col-md-5'+"'>").append(infor)
									.appendTo("#echarts");
						
						console.log(testssss);
						
						testchars(Echarts.init(document.getElementById(ret['yield'][i]['OrderNumber']), 'dark'),ret['yield'][i]);
					}
					
				}
			});
		
			
		}
		


		function testchars(echar,objs){
			LMS=objs['yield_LM'].split('%');//亮度切割98%(100%)
			CIES=objs['yield_CIE'].split('%');
			VFS=objs['yield_VF'].split('%');
			YieldS = [LMS[0],CIES[0],VFS[0]];
			Proportion = [LMS[1].substr(1,LMS[1].length),CIES[1].substr(1,CIES[1].length),VFS[1].substr(1,VFS[1].length)];
			
			
			var posList = [
				'left', 'right', 'top', 'bottom',
				'inside',
				'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
				'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
			];
			var app = {};
			app.configParameters = {
				rotate: {
					min: -90,
					max: 90
				},
				align: {
					options: {
						left: 'left',
						center: 'center',
						right: 'right'
					}
				},
				verticalAlign: {
					options: {
						top: 'top',
						middle: 'middle',
						bottom: 'bottom'
					}
				},
				position: {
					options: Echarts.util.reduce(posList, function (map, pos) {
						map[pos] = pos;
						return map;
					}, {})
				},
				distance: {
					min: 0,
					max: 100
				}
			};

			app.config = {
				rotate: 90,
				align: 'left',
				verticalAlign: 'middle',
				position: 'insideBottom',
				distance: 15,
				onChange: function () {
					var labelOption = {
						normal: {
							rotate: app.config.rotate,
							align: app.config.align,
							verticalAlign: app.config.verticalAlign,
							position: app.config.position,
							distance: app.config.distance
						}
					};
					myChart.setOption({
						series: [{
							label: labelOption
						}, {
							label: labelOption
						}, {
							label: labelOption
						}, {
							label: labelOption
						}]
					});
				}
			};


			var labelOption = {
				normal: {
					show: true,
					position: app.config.position,
					distance: app.config.distance,
					align: app.config.align,
					verticalAlign: app.config.verticalAlign,
					rotate: app.config.rotate,
					formatter: '{c}',
					fontSize: 16,
					rich: {
						name: {
							textBorderColor: '#fff'
						}
					}
				}
			};
            echar.setOption({
				title: {
                    text: objs['OrderNumber'],//图的主题
                },
                color: ['#4cabce', '#e5323e', ],
				tooltip: {
					trigger: 'axis',
					axisPointer: {
						type: 'shadow'
					}
				},
				legend: {
					data: ['实际良率%', '目标良率%']
				},
				toolbox: {
					show: true,
					orient: 'vertical',
					left: 'right',
					top: 'center',
					feature: {
						mark: {show: true},
						dataView: {show: true, readOnly: false},
						magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
						restore: {show: true},
						saveAsImage: {show: true}
					}
				},
				calculable: true,
				xAxis: [
					{
						type: 'category',
						axisTick: {show: false},
						data: xAx
					}
				],
				yAxis: [
					{
						type: 'value'
					}
				],
				series: [
					{
						name: '实际良率%',
						type: 'bar',
						barGap: 0,
						label: labelOption,
						data: YieldS
					},
					{
						name: '目标良率%',
						type: 'bar',
						label: labelOption,
						data: Proportion
					},
					
				]
            });
		}
            $(window).resize(function () {
                //myChart.resize();
				// myChartRa1.resize();
				// myChartFlux.resize();
				// myChartVF.resize();
				// myChartColor.resize();
				test.resize();
            });

            $(document).on("click", ".btn-checkversion", function(){
                top.window.$("[data-toggle=checkupdate]").trigger("click");
            });
			
        }
    };
    return Controller;
});